<?php

namespace app\common\model;

use think\Db;
use think\Model;

/**
 * 会员督学
 */
class UserSupervisor extends Model
{
    protected $name = "user_supervisor";























    /**-------------教师端------------------------------------------------------------------------------ */
    /**
     * 教师端获取学生列表
     */
    public function getTeacherStudents($teacher_id)
    {
        // 查询老师的所有学生，根据user_id去重
        $students = self::alias('us')
            ->join('user u', 'us.user_id = u.id', 'LEFT')  //关联用户表获取学生信息
            ->field('us.user_id, u.nickname, u.avatar, u.mobile')
            ->where('us.teacher_id', $teacher_id)
            ->where('us.end_time', '>', time())
            ->where('us.user_id', '>', 0)  // 确保有学生ID
            ->order('us.createtime DESC')  // 按创建时间倒序
            ->paginate();
        return $students;
    }


    /**
     * 获取一个学生督学列表信息
     * @Author Ixiangang
     * @DateTime 2025-08-18
     * @param [type] $user_id
     */
    public function getSupervisionList($user_id, $type)
    {
        $list = Db::name('supervision')->where(function ($query) use ($user_id, $type) {
            # 待批改
            if ($type == 1) {
                $query->where('teacher_content','eq', '');
                $query->where('teacher_pic','eq', '');
            } 
            # 已批改
            if($type == 2) {
                $query->where('user_id', $user_id);
                 $query->where('teacher_content','neq', '');
                $query->where('teacher_pic','neq', '');
            }
            $query->where('user_id', $user_id);
        })
        ->order('createtime DESC')  // 按创建时间倒序
        ->select();
        foreach ($list as &$v) {
            $v['is_end'] = $v['end_time'] > time() ? 1 : 0; #1=未结束,0=已结束
        }
        return $list;
    }
}
